// components/WeatherTable/WeatherTbale.js
const utils = require('../../utils/util.js')
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        weatherweek: {
            type: Object
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        daylist: []
    },
    observers: {
        'weatherweek': function (val) {
            if (val.code != undefined) {
                this.tableTime(val)
            }
        }
    },
    lifetimes: {

    },
    /**
     * 组件的方法列表
     */
    methods: {
        tableTime(val) {
            var showday = [];
            let day = ['今天', '明天', '后天']
            let week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
            val.daily.forEach((element, index) => {
                if (index <= 2) {
                    showday.push({
                        Fxdate: day[index],
                        textDay: element.textDay,
                        iconDay: element.iconDay,
                        iconNight: element.iconNight,
                        tempMax: element.tempMax,
                        tempMin: element.tempMin

                    })
                } else {
                    showday.push({
                        Fxdate: week[new Date(element.fxDate).getDay()],
                        textDay: element.textDay,
                        iconDay: element.iconDay,
                        iconNight: element.iconNight,
                        tempMax: element.tempMax,
                        tempMin: element.tempMin

                    })
                }
            });
            this.setData({
                daylist: showday
            })
        }
    }
})